/*
* 文 件 名:  PopedomDAOImpl.java
* 版    权:  Tydic Technologies Co., Ltd. Copyright 1993-2012,  All rights reserved
* 描    述:  权限操作接口实现
* 修 改 人:  aganzhoul
* 修改时间:  2012-9-20
* 跟踪单号:  <跟踪单号>
* 修改单号:  <修改单号>
* 修改内容:  <修改内容>
*/
package com.tydic.simple.dao.user.impl;

import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import com.tydic.framework.dao.AbstractIbatisDAO;
import com.tydic.framework.dataobject.ResultDTO;
import com.tydic.framework.exception.DAOException;
import com.tydic.simple.dao.user.IPopedomDAO;
import com.tydic.simple.dto.user.PopedomDTO;
import com.tydic.simple.model.user.Popedom;

/**
* 权限操作接口实现
* 
* @author  aganzhoul
* @version  [1.0, 2012-9-21]
* @since  [权限管理/1.0]
*/
public class PopedomDAOImpl extends AbstractIbatisDAO implements IPopedomDAO {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(PopedomDAOImpl.class);
    
    /** {@inheritDoc} */
    @Override
    public Long savePopedom(Popedom popedom)
        throws DAOException {
        try {
            sqlMapClient.insert("user.INSERT_POPEDOM", popedom);
        }
        catch (SQLException e) {
            LOGGER.error("savePopedom exception", e);
            throw new DAOException("savePopedom exception", e);
        }
        return popedom.getPopedomId();
    }
    
    /** {@inheritDoc} */
    @Override
    public int deletePopedomByCode(String popedomCode)
        throws DAOException {
        try {
            return sqlMapClient.delete("user.DELETE_POPEDOM_BY_CODE", popedomCode);
        }
        catch (SQLException e) {
            LOGGER.error("deletePopedomByCode exception", e);
            throw new DAOException("deletePopedomByCode exception", e);
        }
    }
    
    /** {@inheritDoc} */
    @Override
    public Popedom findPopedomByCode(String popedomCode)
        throws DAOException {
        try {
            return (Popedom)sqlMapClient.queryForObject("user.FIND_POPEDOM_BY_CODE", popedomCode);
        }
        catch (SQLException e) {
            LOGGER.error("findPopedomByCode exception", e);
            throw new DAOException("findPopedomByCode exception", e);
        }
    }
    
    /** {@inheritDoc} */
    @SuppressWarnings("unchecked")
    @Override
    public ResultDTO<Popedom> findPopedom(PopedomDTO popedomDTO)
        throws DAOException {
        ResultDTO<Popedom> result = new ResultDTO<Popedom>();
        try {
            result.setResult(sqlMapClient.queryForList("user.FIND_POPEDOM", popedomDTO));
            BeanUtils.copyProperties(popedomDTO.getPagination(), result.getPagination());
            result.getPagination()
                .setTotal((Integer)sqlMapClient.queryForObject("user.FIND_POPEDOMT_COUNT", popedomDTO));
        }
        catch (SQLException e) {
            LOGGER.error("findPopedom exception", e);
            throw new DAOException("findPopedom exception", e);
        }
        return result;
    }
    
}
